#include <QObject>
#include <QPushButton>
#include <QTimer>
#include "mainwindow.h"
#include "debugwindow.h"
#include <QIcon>

debugwindow::debugwindow(QWidget *parent)
{
    test.setParent(this);
    test.setText("test");
    //test.setMaximumSize(50,50);
    // test.setMinimumSize(50,50);
    test.show();
    //a.setParent(this);
    //a.move(50,50);
    //a.show();
    icon_init(&a,50,30);
    icon_init(&star_num,50,45);
    icon_init(&star_res,50,60);
    icon_init(&star_poplim,50,75);
    icon_init(&star_pop,50,90);
    icon_init(&star_owner,50,105);
    icon_init(&civ_num,50,120);
    icon_init(&civ_res,50,135);
    icon_init(&civ_owned,50,150);
    icon_init(&civ_income,50,165);
    icon_init(&civ_total_pop,50,180);
    icon_init(&civ_contacts,50,195);
    icon_init(&civ_pop_upkeep,50,210);
    icon_init(&civ_research,50,225);
    icon_init(&civ_milit,50,240);
    icon_init(&civ_science,50,255);
    icon_init(&civ_type,50,270);
    icon_init(&civ_friends,50,285);
    icon_init(&civ_opponents,50,300);
    icon_init(&civ_enemies,50,315);
    icon_init(&civ_num_wars,50,330);
    icon_init(&total_wars,50,345);
    icon_init(&civ_power,50,360);
    icon_init(&star_def,50,375);
    icon_init(&civ_defcon,50,390);

    move(900,0);
    setFixedSize(300,600);

    QTimer *timer = new QTimer(this);   //初始化一个定时器。
    connect(timer, &QTimer::timeout, this, &debugwindow::update);   //设置信号与槽 ，槽函数update()需要再类中声明一下。
    timer->start(10 / 1);    //设置定时器刷新频率，即变量刷新频率。


    //setWindowFlags(Qt::CustomizeWindowHint|Qt::FramelessWindowHint);
    show();
}

void debugwindow::icon_init(QLabel* n, int x,int y)
{
    n->setParent(this);
    n->move(x,y);
    n->show();
}

void debugwindow::update()
{
    if(showing!=NULL)
    {
        char buffer[256];

        sprintf(buffer, "资源:%d",showing->res);
        star_res.setText(buffer);
        star_res.setText(buffer);
        star_res.adjustSize();

        sprintf(buffer, "人口上限:%d",showing->poplim);
        star_poplim.setText(buffer);
        star_poplim.setText(buffer);
        star_poplim.adjustSize();

        sprintf(buffer, "人口数量:%d",showing->pop);
        star_pop.setText(buffer);
        star_pop.setText(buffer);
        star_pop.adjustSize();


        sprintf(buffer, "星系序号:%d",showing->n);
        star_num.setText(buffer);
        star_num.setText(buffer);
        star_num.adjustSize();

        sprintf(buffer, "星系防御力:%f",showing->def);
        star_def.setText(buffer);
        star_def.setText(buffer);
        star_def.adjustSize();

        if(showing->owner!=NULL)
        {
            sprintf(buffer, "文明存储资源:%d",showing->owner->resource);
            civ_res.setText(buffer);
            civ_res.setText(buffer);
            civ_res.adjustSize();
            civ_res.show();

            sprintf(buffer, "星系所有者:%d号文明",showing->owner->num);
            star_owner.setText(buffer);
            star_owner.setText(buffer);
            star_owner.adjustSize();
            star_owner.show();

            sprintf(buffer, "文明占有星系数:%d",showing->owner->owned);
            civ_owned.setText(buffer);
            civ_owned.setText(buffer);
            civ_owned.adjustSize();
            civ_owned.show();

            sprintf(buffer, "文明收入:%f",showing->owner->income);
            civ_income.setText(buffer);
            civ_income.setText(buffer);
            civ_income.adjustSize();
            civ_income.show();

            sprintf(buffer, "文明总人口:%d",showing->owner->total_pop);
            civ_total_pop.setText(buffer);
            civ_total_pop.setText(buffer);
            civ_total_pop.adjustSize();
            civ_total_pop.show();

            sprintf(buffer, "文明已经建立的外交关系:%d",showing->owner->contacts);
            civ_contacts.setText(buffer);
            civ_contacts.setText(buffer);
            civ_contacts.adjustSize();
            civ_contacts.show();

            sprintf(buffer, "文明的人口维护费:%f",showing->owner->pop_upkeep);
            civ_pop_upkeep.setText(buffer);
            civ_pop_upkeep.setText(buffer);
            civ_pop_upkeep.adjustSize();
            civ_pop_upkeep.show();

            sprintf(buffer, "文明的科研投入:%f",showing->owner->milit);
            civ_research.setText(buffer);
            civ_research.setText(buffer);
            civ_research.adjustSize();
            civ_research.show();

            sprintf(buffer, "文明的军事投入:%f",showing->owner->science_add);
            civ_milit.setText(buffer);
            civ_milit.setText(buffer);
            civ_milit.adjustSize();
            civ_milit.show();

            sprintf(buffer, "文明的科技水平:%f",showing->owner->science);
            civ_science.setText(buffer);
            civ_science.setText(buffer);
            civ_science.adjustSize();
            civ_science.show();

            sprintf(buffer, "文明类型:%d",showing->owner->type);
            civ_type.setText(buffer);
            civ_type.setText(buffer);
            civ_type.adjustSize();
            civ_type.show();

            sprintf(buffer, "友好关系数:%d",showing->owner->friends);
            civ_friends.setText(buffer);
            civ_friends.setText(buffer);
            civ_friends.adjustSize();
            civ_friends.show();

            sprintf(buffer, "对手关系数:%d",showing->owner->opponents);
            civ_opponents.setText(buffer);
            civ_opponents.setText(buffer);
            civ_opponents.adjustSize();
            civ_opponents.show();

            sprintf(buffer, "敌对关系数:%d",showing->owner->enemies);
            civ_enemies.setText(buffer);
            civ_enemies.setText(buffer);
            civ_enemies.adjustSize();
            civ_enemies.show();

            sprintf(buffer, "正在进行的战争:%d",showing->owner->num_wars);
            civ_num_wars.setText(buffer);
            civ_num_wars.setText(buffer);
            civ_num_wars.adjustSize();
            civ_num_wars.show();

            sprintf(buffer, "文明军事力量:%f",showing->owner->power);
            civ_power.setText(buffer);
            civ_power.setText(buffer);
            civ_power.adjustSize();
            civ_power.show();

            sprintf(buffer, "文明战备等级:%f",showing->owner->defcon);
            civ_defcon.setText(buffer);
            civ_defcon.setText(buffer);
            civ_defcon.adjustSize();
            civ_defcon.show();
        }
        if(showing->owner==NULL)
        {
            civ_res.hide();
            civ_owned.hide();
            star_owner.hide();
            civ_income.hide();
            civ_total_pop.hide();
            civ_contacts.hide();
            civ_pop_upkeep.hide();
            civ_research.hide();
            civ_milit.hide();
            civ_science.hide();
            civ_num_wars.hide();
            civ_power.hide();
            civ_defcon.hide();
        }
    }
}
//QLabel civ_pop_upkeep;
//QLabel civ_research;
//QLabel civ_milit;
//QLabel civ_science;

